package com.hopu.blb_erp.service.impl;

import com.hopu.blb_erp.mapper.RoleFunMapper;
import com.hopu.blb_erp.entity.RoleFun;
import com.hopu.blb_erp.service.RoleFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoleFunServiceImpl implements RoleFunService {

    @Autowired
    private RoleFunMapper roleFunMapper;

    @Override
    public String add(RoleFun roleFun) {
        // 添加前查看角色和权限的关系是否存在
        RoleFun roleFun1 = roleFunMapper.select(roleFun);
        if(roleFun1 == null){
            roleFunMapper.insert(roleFun);
            return "ok";
        }else {
            return "exists";
        }
    }

    @Override
    public RoleFun find(RoleFun roleFun) {
        return roleFunMapper.select(roleFun);
    }

    @Override
    public String remove(RoleFun roleFun) {
        // 添加前查看角色和权限的关系是否存在
        RoleFun roleFun1 = roleFunMapper.select(roleFun);
        if(roleFun1 != null){
            roleFunMapper.delete(roleFun);
            return "ok";
        }else {
            return "noexists";
        }
    }

    @Override
    public void modify(RoleFun roleFun) {
        roleFunMapper.update(roleFun);
    }
}
